package com.cn.demo4.service.impl;

import com.cn.demo4.entity.LayoutEntity;
import com.cn.demo4.mapper.LayoutMapper;
import com.cn.demo4.service.ILayoutService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import redis.clients.jedis.Jedis;

import java.util.List;

@Service
public class LayoutServiceImpl implements ILayoutService {
    @Autowired
    private LayoutMapper layoutMapper;
    @Override
    public List<LayoutEntity> findAll(LayoutEntity layoutEntity) {
        return layoutMapper.findAll(layoutEntity);
    }

    @Override
    public int getCount(LayoutEntity layoutEntity) {
        return layoutMapper.getCount(layoutEntity);
    }

    @Override
    public LayoutEntity findById(Integer id) {
        return layoutMapper.findById(id);
    }

    @Override
    public String add(LayoutEntity layoutEntity) {
        int result = layoutMapper.add(layoutEntity);
        if(result == 1) {
            Jedis jedis = new Jedis();
            jedis.flushDB();
        }
        //返回的是数据库影响条数故是int类型,当又数据更新是给一个标识符：success，反之亦然
        return result == 1 ? "success" : "error";
    }

    @Override
    public String update(LayoutEntity layoutEntity) {
        int result = layoutMapper.update(layoutEntity);
        if(result == 1) {
            Jedis jedis = new Jedis();
            jedis.flushDB();
        }
        //返回的是数据库影响条数故是int类型,当又数据更新是给一个标识符：success，反之亦然
        return result == 1 ? "success" : "error";
    }

    @Override
    public int del(Integer id) {
        int result = layoutMapper.del(id);
        if(result == 1) {
            Jedis jedis = new Jedis();
            jedis.flushDB();
        }
        //返回的是数据库影响条数故是int类型,当又数据更新是给一个标识符：success，反之亦然
        return result;
    }

    @Override
    public List<LayoutEntity> getLayoutModelListForHome() {
        return layoutMapper.getLayoutModelListForHome();
    }
}
